package com.samuel.learing.controller.javaBase;


import com.google.common.collect.Lists;
import com.samuel.learing.Person;

import java.util.Comparator;
import java.util.List;
import java.util.Random;

import static java.util.stream.Collectors.toList;

/**
 * @company: mamahao.com
 * @author: taozhaoyang
 * @time: 2018-01-04 15:15
 * @version: 1.0
 * @desc: java8 排序
 **/
public class ComparatorSort {


    public static void main(String[] args) {
        List<Person> personList = Lists.newArrayList();

        Person person;
        for (int i = 0; i <10 ; i++) {
             person = new Person();
             Random random = new Random();
            person.setId(random.nextInt(10+i));
            person.setName("robot"+i);
            person.setAge(10+i);
            if(i>8){
                person.setAge(99999);
            }

            personList.add(person);
        }

        personList.forEach(
                a->{
                    System.out.println(a.toString());
                }
        );

        //personList.sort(Comparator.comparing(Person::getId).reversed().thenComparing(Person::getAge).reversed());

        personList.sort(Comparator.comparing(Person::getAge));
        personList.stream().map(a->{
            if(a.getAge()==99999) a.setAge(null);
            return a;
        }).collect(toList());

        System.out.println("------------------------");
        personList.forEach(
                a->{
                    System.out.println(a.toString());
                }
        );
    }





}